import request from '@/utils/request'

export function getCategoryReq() {// 获取产品类别
  return request({
    url: '/admin/category/getCategory',
    method: 'GET',
  })
}

export function getBrandById(params) {// 获取品牌类别
  return request({
    url: '/admin/brand/getBrand',
    method: 'GET',
    params
  })
}


export function getProductList(data) {// 获取产品列表
  return request({
    url: '/admin/product/list',
    method: 'POST',
    data
  })
}

export function getProductDetail(params) {// 获取产品详情
  return request({
    url: '/admin/product/detail',
    method: 'GET',
    params
  })
}

export function upload(data,callback) {// 上传产品图片
  return request({
    url: '/file/uploadMulti',
    method: 'POST',
/*    onUploadProgress: progressEvent => {
      // progressEvent.loaded:已上传文件大小
      // progressEvent.total:被上传文件的总大小
      this.progressPercent = (progressEvent.loaded / progressEvent.total * 100)
    },*/
    onUploadProgress: progressEvent => {
      // 原生获取上传进度的事件
      if (progressEvent.lengthComputable) {
        callback && callback(progressEvent);
      }
    },
/*    headers: {
      'Content-Type': 'multipart/form-data'
    },*/
    data
  })
}

export function uploadProduct(data,callback) {// 上传产品图片
  return request({
    url: '/admin/product/add',
    method: 'POST',
    onUploadProgress: progressEvent => {
      if (progressEvent.lengthComputable) {
        callback && callback(progressEvent);
      }
    },
    data
  })
}

export function modifyProductStateReq(params) {// 修改产品规格状态
  return request({
    url: '/admin/product/modifyProductState',
    method: 'GET',
    params
  })
}

export function modifySpecsStockReq(params) {// 修改产品规格库存
  return request({
    url: '/admin/product/modifySpecsStock',
    method: 'GET',
    params
  })
}

export function modifySpecsStateReq(params) {// 修改产品规格状态
  return request({
    url: '/admin/product/modifySpecsState',
    method: 'GET',
    params
  })
}


export function preheatReq() {// 预热
  return request({
    url: '/admin/product/preheat',
    method: 'GET',
  })
}
